import { ref } from "vue";
import { defineStore } from "pinia";
import { getCart } from "@/service/cart";
export const useCartStore = defineStore("cart", () => {
  const count = ref(0);
  async function updateCart() {
    // 解构赋值data属性,data不存在或者为undefined，则默认值赋值为一个空数组[]。
    const { data = [] } = await getCart(); //获取购物车数量接口
    count.value = data.length; //购物车数组商品的数量长度等于购物车数量
  }

  return { count, updateCart };
});
